package com.jxl.dnd.charactercreator.vo.skills
{
	import flash.events.EventDispatcher;

	[Bindable]
	public class Skill extends EventDispatcher
	{
		
		public var name:String;
		public var primaryAbility:String;
		public var description:String;
		public var parentSkill:Skill;
		public var childSkill:Skill;
		
		public function Skill():void
		{
			super();
		}
		
		public function buildFromObject(obj:Object):void
		{
			this.name					= name;
			this.primaryAbility			= primaryAbility;
			this.description			= description;
			if(obj.parentSkill != null)
			{
				this.parentSkill = new Skill();
				this.parentSkill.buildFromObject(obj.parentSkill);
			}
			if(obj.childSkill != null)
			{
				this.childSkill	= new Skill();
				this.childSkill.buildFromObject(childSkill);
			}
		}
		
		public function toObject():Object
		{
			var obj:Object = new Object();
			obj.name					= name;
			obj.primaryAbility			= primaryAbility;
			obj.description				= description;
			if(parentSkill != null)
			{
				obj.parentSkill			= parentSkill.toObject();
			}
			if(childSkill != null)
			{
				obj.childSkill			= childSkill.toObject();
			}
			return obj;
		}
		
		public function toXML():XML
		{
			// TODO: handle parent and child skill(s)
			var myXML:XML = 
				<skill>
					<name>{name}</name>
					<primaryability>{primaryAbility}</primaryability>
					<description>{description}</description>
				</skill>;
			return myXML;
		}
		
		public function buildFromXML(xml:XML):void
		{
			for each(var skillNode:XML in xml..skill)
			{
				name 			= skillNode.name;
				primaryAbility	= skillNode.primaryability;
				description		= skillNode.description;
			}
		}
		
	}
}